package com.kienbk1910.productmanager.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{
	public static int DATA_BASE_VERSION =2;
	public static String DATA_BASE_NAME="productmanager";
	public static String TABLE_NAME="product";
	public static String ID="_id";
	public static String NAME="name";
	public static String MANUFACTURER ="manufacturer";
	public static String COST ="cost";
	public static String COUNT ="count";
	public static String NOTE ="note";
	public static String BAR_CODE = "barcode";
	public static String IMAGE_PATH ="imagepath";
	public static String POST_TIME ="postTime";
	static final String CREATE_TABLE = 
		      " CREATE TABLE " + TABLE_NAME +
		      " ("+ID+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
		      NAME+" TEXT NOT NULL, " +
		      MANUFACTURER+" TEXT NOT NULL,"+
		      COST +" INTEGER,"+
		      COUNT +" INTEGER,"+
		      NOTE+" TEXT,"+
			  BAR_CODE +" TEXT,"+
			  IMAGE_PATH+ " TEXT,"+
			  POST_TIME +" INTEGER);";
		 
	public DBHelper(Context context) {
		super(context, DATA_BASE_NAME, null, DATA_BASE_VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(CREATE_TABLE);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " +  TABLE_NAME);
        onCreate(db);
	}

}
